//思路：有效的括号


import javax.management.remote.rmi._RMIConnection_Stub;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        System.out.println(isValid("){"));
   }
    public static boolean isValid(String s) {

       Stack<Character> s1=new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch=s.charAt(i);
            if(ch=='('||ch=='['||ch=='{'){
                s1.push(ch);
            }else{
                if(s1.empty()){
                    return false;
                }
                char c=s1.pop();
                if((c=='('&&ch!=')')||(c=='['&&ch!=']')||(c=='{'&&ch!='}')){
                    return false;
                }
            }
        }
        if(s1.empty()){
            return true;
        }else{
            return false;
        }
        }
}














